package com.google.code.japndroid;

import com.google.code.packetkiller.Constants;
import com.google.code.packetkiller.dao.ConnectionDao;
import com.google.code.packetkiller.dao.DaoFactory;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;

public class PacketKillReciever extends BroadcastReceiver {
	
	int pitch;
	
	@Override
	public void onReceive(Context context, Intent intent) {

		SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(context);
		//long interval = Long.parseLong(preference.getString("pref_itvl_value","0"));
		//pitch = Integer.parseInt(preference.getString("pref_orientation_value","0"));
		
		//Intent serviceIntent = new Intent(context,PacketKillService.class);
		//serviceIntent.setAction("start");
		//serviceIntent.putExtra("interval",interval);
		//serviceIntent.putExtra("pitch",pitch);	
		
		if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ){
			//Prefs prefs = new Prefs(context);
			//if( ! prefs.isLastStatusConnected() ){
			//	context.startService(serviceIntent);
			//}
		}else{
			Bundle extras = intent.getExtras();
			boolean isEnabled = extras.getBoolean(Constants.STATUS_EXTRA);
			//boolean isDeviceUp = extras.getBoolean("isDeviceUp");
			//boolean fromSensor = extras.getBoolean("formSensor");
			ConnectionDao connectionDao = DaoFactory.getDao(context,false);
			connectionDao.setDataEnabled(isEnabled);
			
			/* int mode = 0;
			if( ! isEnabled ){
				//mode = 1;
				if(fromSensor ){
					ConnectionDao connectionDao = DaoFactory.getDao(context,false);
					if(isDeviceUp){
						mode = 2;
						context.stopService(serviceIntent);
						connectionDao.setDataEnabled(true);
					}else{
						mode = 3;
						connectionDao.setDataEnabled(false);
						context.startService(serviceIntent);
					}
				}else{
					mode = 4;
					context.startService(serviceIntent);
				}
			}else{
				mode = 5;
				context.stopService(serviceIntent);
			}
			*/
			Log.v("PACKET KILLER","3G enable is " + isEnabled);

		}
	}
}
